package com.sherry.uitils.auth;

import com.qingqing.common.auth.domain.User;
import com.qingqing.common.auth.domain.UserType;
import com.qingqing.common.util.UserIdEncoder;
import com.qingqing.common.util.encode.TripleDESUtil;

public class IdEncoder {
	
	public static String encodeUser(UserType userType, long userId){
		User user = new User(userType, userId);
		return UserIdEncoder.encodeUser(user);
	}

	public static String encodeUser(int userType, long userId){
		User user = new User(UserType.valueOf(userType), userId);
		return UserIdEncoder.encodeUser(user);
	}

	public static String encodeUser(long userId){
		User user = new User(UserType.student, userId);
		return UserIdEncoder.encodeUser(user);
	}
	
	public static String encodeTeacher(long userId){
		User user = new User(UserType.teacher, userId);
		return UserIdEncoder.encodeUser(user);
	}
	
	public static String encodeTa(long userId){
		User user = new User(UserType.ta, userId);
 		return UserIdEncoder.encodeUser(user);
	}
	public static String encodeAdmin(long userId){
		User user = new User(UserType.admin, userId);
		return UserIdEncoder.encodeUser(user);
	}
	
	public static String encodeExpert(long userId){
		User user = new User(UserType.expert, userId);
		return UserIdEncoder.encodeUser(user);
	}
	
	public static String encodeStaff(long userId){
		User user = new User(UserType.staff, userId);
		return UserIdEncoder.encodeUser(user);
	}

	public static String encodeSystem(long userId){
		User user = new User(UserType.system, userId);
		return UserIdEncoder.encodeUser(user);
	}

	//手机号解密
	public static String decodePhone(String decodePhone) throws Exception {
		return TripleDESUtil.decrypt(decodePhone);
	}

	//手机号加密
	public static String encodePhone(String decodePhone) throws Exception {
		return TripleDESUtil.encrypt(decodePhone);
	}
	
	public static User decodeUser(long qingqingUserId){		
		return UserIdEncoder.decodeUser(String.valueOf(qingqingUserId));
	}
	
	public static User decodeUser(String qingqingUserId){		
		return UserIdEncoder.decodeUser(qingqingUserId);
	}
	
	public static String decodeStudent(String qingqingUserId){
		return String.valueOf(UserIdEncoder.decodeUser(qingqingUserId).getUserId());
	}
	
	public static User decodeStudent(long qingqingUserId){
		return UserIdEncoder.decodeUser(String.valueOf(qingqingUserId));
	}
	
	public static String decodeTeacher(String qingqingUserId){
		return String.valueOf(UserIdEncoder.decodeUser(qingqingUserId).getUserId());
	}
	
	public static Long decodeTeacher(long qingqingUserId){
		return UserIdEncoder.decodeUser(String.valueOf(qingqingUserId)).getUserId();
	}
	
	public static String decodeTa(String qingqingUserId){
		return String.valueOf(UserIdEncoder.decodeUser(qingqingUserId).getUserId());
	}
	
	public static User decodeTa(long qingqingUserId){
		return UserIdEncoder.decodeUser(String.valueOf(qingqingUserId));
	}

	public static long decodeUserId(String qingqingUserId){
		return UserIdEncoder.decodeUser(qingqingUserId).getUserId();
	}

	public static long decodeTeacherId(String qingqingUserId){
		return UserIdEncoder.decodeUser(qingqingUserId).getUserId();
	}

}